package org.tloss.web.editor.model.oper.logical;

import org.tloss.web.editor.model.oper.math.MathOperand;

public class CompareLogical extends Logical {
	MathOperand operand1;
	MathOperand operand2;
	CompareOperator operator;

	public MathOperand getOperand1() {
		return operand1;
	}

	public void setOperand1(MathOperand operand1) {
		this.operand1 = operand1;
	}

	public MathOperand getOperand2() {
		return operand2;
	}

	public void setOperand2(MathOperand operand2) {
		this.operand2 = operand2;
	}

	public CompareOperator getOperator() {
		return operator;
	}

	public void setOperator(CompareOperator operator) {
		this.operator = operator;
	}

	@Override
	public String getDisplayText() {
		if (operator == null || operand1 == null
				|| (operator.supportTwoOperand() && operand2 == null)) {
			return " Edit me!";
		}
		if (operator.supportTwoOperand())
			return "(" + operand1.getDisplayText() + " "
					+ operator.getDisplayText() + " "
					+ operand2.getDisplayText() + ")";
		else if (!operator.supportTail()) {
			return "" + operator.getDisplayText() + "("
					+ operand1.getDisplayText() + ")";
		} else {
			return "" + operand1.getDisplayText() + " "
					+ operator.getDisplayText();
		}

	}

	@Override
	public String generate(int type, Object[] data) {
		// TODO Auto-generated method stub
		if (operator == null || operand1 == null
				|| (operator.supportTwoOperand() && operand2 == null)) {
			return " Edit me!";
		}
		if (operator.supportTwoOperand())
			return "(" + operand1.generate(type, data) + " "
					+ operator.generate(type, data) + " "
					+ operand2.generate(type, data)+ ")";
		else if (!operator.supportTail()) {
			return "" + operator.generate(type, data) + "("
					+ operand1.generate(type, data) + ")";
		} else {
			return "" + operand1.generate(type, data) + " "
					+ operator.generate(type, data);
		}
	}

}
